//
use "$temp/acs_master_kid_sample", clear
keep if age<=45 //restrict to avoid mechanically reducing fertility rate
gen married=0
replace married = 1 if marst == 1 | marst == 2
gen kid = (nchild>0) //recode kid

probit kid hc*  i.bpl ib1.racetype if hc<3.0 & coll & married [fw = perwt], robust 
probit kid hc*  i.bpl ib1.racetype if hc<3.0 & coll & !married [fw = perwt], robust 

probit kid hc*  i.bpl ib1.racetype if hc<3.0 & !coll & married [fw = perwt], robust 
probit kid hc*  i.bpl ib1.racetype if hc<3.0 & !coll & !married [fw = perwt], robust 



//comptue probability of having kids
use "$temp/acs_master_kid_sample", clear
keep if !coll
keep if age<=45 //restrict to avoid mechanically reducing fertility rate

//recode marriage
gen married=0
replace married = 1 if marst == 1 | marst == 2
gen kid = (nchild>0) //recode kid

*****kid polynomials for kids, based on birth place -- MARRIED*****
preserve
keep if married
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	noi di "`fip'"
	qui probit kid hc* if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	
	qui su kid if hc>3.0 [fw=perwt] //don't have enough observations in all states; have to hack this
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
}
compress
export delimited "$dir/Model/utilities/kid_fertility_probs_marr_noncoll.csv", replace novarn
restore


*****kid polynomials for kids, based on birth place -- UNMARRIED*****
preserve
keep if !married
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	qui probit kid hc* if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	
	qui su kid if hc>3.0 [fw=perwt]
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
}
compress
export delimited "$dir/Model/utilities/kid_fertility_probs_nonmarr_noncoll.csv", replace novarn
restore


****************COLLEGE
//comptue probability of having kids
use "$temp/acs_master_kid_sample", clear

keep if age<=45 //restrict to avoid mechanically reducing fertility rate
keep if coll
//recode marriage
gen married=0
replace married = 1 if marst == 1 | marst == 2
gen kid = (nchild>0) //recode kid

*****kid polynomials for kids, based on birth place -- MARRIED*****
preserve
keep if married
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	noi di "`fip'"
	qui probit kid hc* if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	
	qui su kid if hc>3.0  [fw=perwt]
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
}
compress
export delimited "$dir/Model/utilities/kid_fertility_probs_marr_coll.csv", replace novarn
restore


*****kid polynomials for kids, based on birth place -- UNMARRIED*****
preserve
keep if !married
levelsof bpl, clean local(fips)
foreach fip in `fips'{
	qui probit kid hc* if bpl == `fip' & hc<3.0 [fw = perwt], robust
	local cons`fip' = _b[_cons]
	local hc_`fip' = _b[hc]
	local hc2_`fip' = _b[hc2]
	local hc3_`fip' = _b[hc3]
	
	qui su kid if hc>3.0 [fw=perwt]
	local cap_`fip' = `r(mean)'
}

//turn into data
clear
set obs 50
gen fips = .
gen cons = .
gen b1 = .
gen b2 = .
gen b3 = .
gen cap = .
local counter = 0
foreach fip in `fips'{
	local counter `++counter'
	replace fip = `fip' in `counter'
	replace cons = `cons`fip'' in `counter'
	replace b1 = `hc_`fip'' in `counter'
	replace b2 = `hc2_`fip'' in `counter'
	replace b3 = `hc3_`fip'' in `counter'
	replace cap = `cap_`fip'' in `counter'
}
compress
export delimited "$dir/Model/utilities/kid_fertility_probs_nonmarr_coll.csv", replace novarn
restore

//end of do-file